package com.gitee.huanminabc.demo.spring.monitor.listener;

import com.gitee.huanminabc.demo.spring.monitor.event.Demo1Event;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * @Author huanmin
 * @Date 2024/6/5 下午6:28
 */
@Component
public class Demo1Listener {

    //监听单个事件
    @EventListener(Demo1Event.class)
//    @Order(1)  //值越小，优先级越高
    //@Async  //异步监听 ,尽量自定义线程池
    public void onApplicationEvent(Demo1Event event) {
        System.out.println("监听到事件:" + event.getSource());
    }
    //同时监听多个事件
    @EventListener(value = {Demo1Event.class, Demo1Event.class})
    public void onApplicationEvent1(Demo1Event event) {
        System.out.println("监听到事件:" + event.getSource());
    }
}
